"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const taro_1 = require("@tarojs/taro");
const components_1 = require("@tarojs/components");
const taro_ui_1 = require("taro-ui");
const config_1 = require("../../../config");
const edit_svg_1 = require("./edit.svg");
require("./index.scss");
class default_1 extends taro_1.Component {
    constructor() {
        super(...arguments);
        this.config = {
            navigationBarTitleText: '我的收货地址'
        };
        this.onGoPage = (id, e) => {
            e.stopPropagation();
            taro_1.default.navigateTo({
                url: '/pages/my/address/Profile?id=' + id
            });
        };
        this.onNewAddress = e => {
            e.stopPropagation();
            // 提交收货地址
            taro_1.default.chooseAddress()
                .then(data => {
                return taro_1.default.request({
                    method: 'POST',
                    url: `${config_1.host}/api/v1/addresses`,
                    data,
                    header: {
                        'content-type': 'application/json'
                    }
                })
                    .then(res => {
                    console.log(res);
                    taro_1.default.showToast({ title: `地址保存成功`, icon: 'success', duration: 1000 });
                });
            })
                .catch(e => {
                console.log(e);
                taro_1.default.showToast({ title: '操作失败', icon: 'loading', duration: 1000 });
            });
        };
    }
    componentWillReceiveProps(nextProps) {
        console.log(this.props, nextProps);
    }
    componentWillUnmount() { }
    componentDidShow() { }
    componentDidHide() { }
    render() {
        return (<components_1.View className='address'>
        {Array.from(new Array(16)).map((i, k) => (<components_1.View className='cell' key={i + k}>
                <components_1.View className='content'>
                  <components_1.View className='title'>
                    <components_1.Text className='text'>李泰爱 12345678910</components_1.Text>
                  </components_1.View>
                  <components_1.Text className='brief'>山西省 太原市 小店区 欢度鄂东大道</components_1.Text>
                </components_1.View>
                <components_1.View className='navigate'>
                  <components_1.Image src={edit_svg_1.default} className='icon' onClick={this.onGoPage.bind(this, k)}/>
                </components_1.View>
              </components_1.View>))}
        <components_1.View className='buttonFix'>
          <taro_ui_1.AtButton className='btn' type='primary' onClick={this.onNewAddress}>新增地址</taro_ui_1.AtButton>
        </components_1.View>
      </components_1.View>);
    }
}
exports.default = default_1;
//# sourceMappingURL=index.jsx.map